# Reference: https://github.com/archlinuxarm/PKGBUILDs/blob/d2ee78cab3c298583eb3f3bed4d75970f54885be/core/linux-armv7/config
# Kernel config based on: ~2021 mainline kernel of the linux-armv7 package (5.x mainline) from archlinux arm
# Maintainer: Robert Eckelmann <longnoserob@postmarketos.org>
# Co-Maintainer: exkc <exkc@exkc.moe>

pkgname=linux-postmarketos-marvell
pkgver=6.12.6
pkgrel=0
pkgdesc="mainline (stable) for Marvell SoC"
arch="armv7"
_carch="arm"
_flavor="${pkgname#linux-}"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native pmb:kconfigcheck-community"
makedepends="
	bash
	bc
	bison
	devicepkg-dev
	findutils
	flex
	openssl-dev
	perl
	xz
"
replaces="linux-postmarketos-marvell-dove"

# Source
_config="config-$_flavor.$arch"
source="
	$pkgname-$pkgver.tar.xz::https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/linux-$pkgver.tar.xz
	$_config
"
builddir="$srcdir/linux-$pkgver"

prepare() {
	default_prepare
	cp -v "$srcdir"/$_config .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
}

package() {
	install -Dm644 "$builddir/arch/$_carch/boot/zImage" \
		"$pkgdir/boot/vmlinuz"

	make modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot/ \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}


sha512sums="
35fcfc5044b1bf892b6432a330df26c5601f78f78f416400359f5e08c448255bcf424de611e67ff7ac72d014884d5f3c6c2bddb20d08dd47469df5c0424832f9  linux-postmarketos-marvell-6.12.6.tar.xz
240eb91c2bf270944d2df3e067c9a99a12b03388be50393b49373d13620786eb3bf9da488233a748d06660efaa5bafcf98a2cedd1ea3db46463aeaebca74e69f  config-postmarketos-marvell.armv7
"
